<template>
	<uni-loading v-if="loading"></uni-loading>
	<view class="body" v-else>
		<!--  顶部  -->
		<top-tab :options="stockList" :isLocation="false" @stockChange="stockChange"></top-tab>
		<!--  列表  -->
		<template v-if="inventoryList && inventoryList.length > 0">
			<template v-for="item in inventoryList">
				<view class="panel bottomBorder" @click="inventoryPlanPage(item)">
					<view class="panel_title">
						<view class="panel_title_left">{{ item.stockTakeName }}
							<view class="tag" :class="{review: item.inventoryType === 'review'}">
								{{item.inventoryType === 'review' ? '复盘' : '一盘'}}
							</view>
						</view>

					</view>
					<view class="panel_content">
						<view class="panel_content_row">
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">编码：</view>
								<view class="panel_content_row_item_value">{{ item.realBillNo }}</view>
							</view>
						</view>
					</view>
					<view class="panel_content">
						<view class="panel_content_row">
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">仓库开始：</view>
								<view class="panel_content_row_item_value">{{ item.stockFrom }}</view>

							</view>
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">仓库结束：</view>
								<view class="panel_content_row_item_value">{{ item.stockTo }}</view>
							</view>
						</view>
					</view>
					<view class="panel_content">
						<view class="panel_content_row">
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">全部箱数：</view>
								<view class="panel_content_row_item_value">{{ item.sumBoxCount }}</view>
							</view>
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">已扫箱数：</view>
								<view class="panel_content_row_item_value">{{(item.inventoryType === 'review' ? item.reviewSweptCount : item.sweptCount) || 0}}</view>
							</view>
						</view>
					</view>
				</view>
			</template>
		</template>
		<uni-empty-info v-else label="暂无盘点方案"></uni-empty-info>
	</view>
</template>
<script>
	import topTab from "@/components/top-tab/top-tab"
	import minActionSheet from '@/components/min-action-sheet/min-action-sheet'
	import uniLoading from "../../vBase/components/uni-loading/uni-loading"
	import uniEmptyInfo from "../../vBase/components/uni-empty-info/uni-empty-info"
	import ScaningPopup from "@/components/popup/materialPopup.vue"
	import BarnPopup from "@/components/popup/barnPopup.vue"

	export default {
		components: {
			topTab,
			minActionSheet,
			uniLoading,
			uniEmptyInfo,
			ScaningPopup,
			BarnPopup
		},
		data() {
			return {
				loading: false,
				inventoryList: [],
				stockList: [],
				stockNo: '',
			}
		},
		async onLoad() {
			await this.getStockList();
			this.initData()
		},
		mounted() {},
		methods: {
			/** 查询仓库*/
			async getStockList() {
				this.loading = true;
				try {
					let {
						res,
						stockList = []
					} = await this.$api.getCustomerStock();
					if (!res) return;
					this.stockList = stockList;
					if (stockList.length) this.stockNo = stockList[0].stockNo;
				} finally {
					this.loading = false;
				}
			},
			/** 初始化数据 */
			initData() {
				if (!this.stockNo) return;
				this.pageConfig = {
					pageIndex: 0,
					pageSize: 20,
					bottomEnd: false,
					bottomLoading: true
				}
				this.inventoryList = []
				this.getUserTask()
			},

			/** 获取数据 */
			async getUserTask() {
				let {
					res,
					data = []
				} = await this.$api.getUserTask({
					stockNo: this.stockNo
				}, {
					loading: true
				});
				if (!res) return;
				this.inventoryList = data;
				this.loading = false;
				this.pageConfig.bottomEnd = true;
				this.pageConfig.bottomLoading = false;
				uni.stopPullDownRefresh();
			},

			/**
			 * 选择仓库
			 * @param e
			 */
			stockChange(e) {
				this.stockNo = this.stockList[e].stockNo
				this.initData()
			},

			/**
			 * 
			 * @param {Object} item
			 */
			inventoryPlanPage(item) {
				this.$navigateTo('/pages/storehouse/inventoryPlan', {
					billNo: item.billNo,
					stockNo: this.stockNo,
					type: !item.stockTakeMethod ? 1 : 0,
					inventoryType: item.inventoryType
				})
			},

			/**
			 * 下拉刷新数据
			 */
			onPullDownRefresh() {
				this.initData()
			},

			/** 上滑加载 */
			onReachBottom() {
				if (!this.pageConfig.bottomEnd) {
					this.pageConfig.pageIndex++
					this.pageConfig.bottomLoading = true
					this.getPurchaseList();
				}
			},
		}
	}
</script>
<style lang="scss" scoped>
	@import "../../static/css/common";

	.bottomBorder {
		border-bottom: 1px solid #F2F6FC;
	}
</style>
